package 剑指offer.demo7;
//https://leetcode.cn/problems/qIsx9U/
/*
看懂题的话其实还是很简单的
 */
public class 滑动窗口的平均值 {
    int[] nums = new int[10086];
    int size, n, i, sum;
    public 滑动窗口的平均值(int size) {
        this.size = size;
    }
    public double next(int val) {
        nums[n++] = val;
        sum += val;
        if (n - i <= size) {
            return 1.0 * sum / (n - i);
        } else {
            sum -= nums[i++];
            return 1.0 * sum / size;
        }
    }
}
